﻿from PyQt5.QtWidgets import QApplication, QLabel, QWidget, QTextEdit, QVBoxLayout, QPushButton
import sys
from GoogleFreeTrans import Translator
from PyQt5.QtGui import QPixmap, QIcon


class TestEdit(QWidget):
    def __init__(self, parent=None):
        super(TestEdit, self).__init__(parent)
        self.resize(800, 670)
        self.textEdit = QTextEdit()
        self.setWindowTitle('ゆかり最好看')
        self.setWindowIcon(QIcon('./head/favicon.ico'))
        self.btn = QPushButton('click')
        self.label3 = QLabel(self)
        self.label3.setPixmap(QPixmap("./head/2.png"))
        # self.label4=QLabel(self)
        # self.label4.setPixmap(QPixmap("./head/4.png"))
        layout = QVBoxLayout()
        layout.addWidget(self.textEdit)
        layout.addWidget(self.btn)
        layout.addWidget(self.label3)
        # layout.addWidget(self.label4)
        self.setLayout(layout)

        self.translator1 = Translator.translator(src='en', dest='ja')

        self.btn.clicked.connect(self.c)

    def c(self):
        eng = self.textEdit.toPlainText()
        ja = self.translator1.translate(eng)
        self.textEdit.setHtml("<font color='red'>" + ja + "</font>")


if __name__ == '__main__':
    try:
        app = QApplication(sys.argv)
        win = TestEdit()
        win.show()

        sys.exit(app.exec_())
    except AttributeError as ae:
        pass
